<?php echo $this->render('header.phtml'); ?>
<label class="title">Quản lý hàng hóa - Đăng tin mua hàng.</label>
<div class="horiz_sep">&nbsp;</div>
<?php
if (isset($this->commodity))
	$commodity = (object) $this->commodity;
if (isset($this->selected_categories))
	$selected_categories = $this->selected_categories;
if (isset($this->errors)){
	$errors = $this->errors;
	if (key_exists("not_enough_money", $errors)) $not_enough_money = $errors['not_enough_money'];
	if (!isset($not_enough_money)){
		if (key_exists("name_null", $errors)) $name_null = $errors['name_null'];
//		if (key_exists("status_null", $errors)) $status_null = $errors['status_null'];
//		if (key_exists("avail_null", $errors)) $avail_null = $errors['avail_null'];
		if (key_exists("price_null", $errors)) $price_null = $errors['price_null'];
		if (key_exists("category_null", $errors)) $category_null = $errors['category_null'];
	}	
}
?>
<form action="<? echo $this -> baseUrl ?>/<?= $this->contextPath ?>/post-buy" method="post" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="5" width="100%">
<?php if (isset($not_enough_money)){ ?>
<tr>
	<td width="100%" colspan="2">
	<p align="center" style="float: left; padding: 0 0 30px 0; margin: 0; width: 100%; color: #ff7300; border: 1px solid #cbddf1; background-color: #eff4fa">
		<br /><br />
		<label style="font-size: 15pt; font-weight: bold;">
			<?= $not_enough_money; ?>
		</label>
	</p>
	</td>
</tr>
<?php } ?>
  	<tr>
    	<th width="15%">Name (*):</th>
    	<td>
    		<input maxlength="150" type="text" name="name" value="<?= $commodity->com_name; ?>" style="width: 250px;"/>
    		<?php if (isset($name_null)){ ?>
				<span style="color:red; font-weight:bold;"><?php echo $name_null; ?></span>
			<?php } ?>
    	</td>
  	</tr>  
  	<tr>
    	<th>Category (*):</th>
    	<td>  
    		<?php if (isset($category_null)){ ?>
				<span style="color:red; font-weight:bold;"><?php echo $category_null; ?></span>
			<?php } ?>  	
    		<table cellpadding="0" cellspacing="0" width="100%">
    		<?php
    			if (isset($this->sections)) {
    				$sections = $this->sections;
    				foreach ($sections as $section){
    		?>
    			<tr>
    				<td>    					
    					<?= $section->sec_name; ?>  
    				</td>
    			</tr>
    			<tr>
    				<td>  				    					
    			<?php
    					foreach ($this->catagories as $category){
    						if ($category->sec_id == $section->sec_id){    							
    							if (!isset($category_null)){
    								$checked = "";			
    								if (isset($selected_categories) != null)			  								
    								foreach ($selected_categories as $key => $value){
    									if ($value == $category->cat_id){
    										$checked = "checked";
    									}
    								}
    							}
    			?>
    										<input type="checkbox" name="category[]" value="<?= $category->cat_id; ?>" <?if (isset($checked)) echo $checked; ?>/><?= $category->cat_name; ?>
    			<?php
    						}
    					}
					}
    			?>
    			</td>
    			</tr>
    			<?php
    			}
    			?>    		
    		</table>    			 		
    	</td>
  	</tr>	
  	
  	<tr>
    	<th>Price (*):</th>
    	<td>
    		<input maxlength="200" type="text" name="price" value="Thỏa thuận" style="width: 250px;"/>
    		<?php if (isset($price_null)){ ?>
				<span style="color:red; font-weight:bold;"><?php echo $price_null; ?></span>
			<?php } ?>
    	</td>
  	</tr>
  	<tr>
    	<th>Vip:</th>
    	<td>
    		<input type="checkbox" name="vip" value="1"/>
    	</td>
  	</tr>
  	<tr>
    	<th colspan="2">Description:</th>
    </tr>
    <tr>
    	<td colspan="2">
    		<textarea name="description" rows="5" style="width:100%;"></textarea>
			<script src="<?= $this->baseUrl ?>/public/scripts/fckeditor/fckeditor.js" type="text/javascript"></script>	
			<script type="text/javascript">
				<!--
				// Automatically calculates the editor base path based on the _samples directory.
				// This is usefull only for these samples. A real application should use something like this:
				// oFCKeditor.BasePath = '/fckeditor/' ;	// '/fckeditor/' is the default value.
				var sBasePath = '<?= $this->baseUrl ?>/public/scripts/fckeditor/' ;
				var oFCKeditor = new FCKeditor( 'description' ) ;
				oFCKeditor.BasePath	= sBasePath ;
				oFCKeditor.ToolbarSet = 'Member';
				oFCKeditor.Height	= 250 ;
				oFCKeditor.ReplaceTextarea() ;
				//-->
			</script>
    	</td>
  	</tr>
  	<tr>
  		<td>Image:</td>
  	</tr>
  	<?php for ($i=0; $i<5; $i++){ ?>
  		<tr>
	  		<td>
	  			<input type="file" name="image_file[]" width="50%"/>
	  		</td>
	  	</tr>
  	<?php }?>  	
  	<tr>    	
    	<td align="left" colspan="2">
    		<input type="submit" name="save" value="Save"/>
    	</td>
  	</tr>
</table>
</form>
<?php echo $this->render('footer.phtml');?> 